include EnotifyLdap

user = 'davidmcd'
#ldap = EnotifyLdap.new

guy = get_person_from_ldap_by_username(user)

#puts "starting lookup"

if !guy.nil?
    puts 'found ' + guy.full_name_and_username
else
    puts 'couldn\'t find ' + user
end


team = get_array_of_employees_from_ldap_by_manager_username(user)

if !team.nil?
  team.each do |newguy|
    puts newguy.full_name_and_username 
  end
else
  puts "no team here"
end

#get_array_of_people_from_ldap_by_manager_username(user).split(':').each do |number|
#    puts "employee" + number
#end

=begin
team = ldap.get_array_of_people_from_ldap_by_manager_username(user)

if !team.nil?
    team.each do |person|
        puts person.full_name_and_username
    end
else
    puts "no team for " + user
end
=end

#get_full_person_from_ldap_by_username('adamm')

#puts "done"

#puts get_person_from_ldap_by_username('parussel').full_name_and_username

#puts userhash['sn']


=begin

def get_direct_reports_for_employee_number(employee_number)
{


    my $ldap = $self->_setup_ldap();


    my $mesg = $ldap->search(
                      base   => SEARCH_BASE,
                      scope  => SEARCH_SCOPE,
                       filter => FIELD_MANAGER_EMPLOYEE_NUMBER."=$employee_number"
                      );


    return $mesg->all_entries();

}

=cut


def authenticate
  authenticate_or_request_with_http_basic do |username, password|
    ldap = Net::LDAP.new :host => 'ldap.host.com', :base => 'ou=active, ou=employees, ou=people, o=host.com'
    ldap.auth 'uid=' + username + ',ou=active,ou=employees,ou=people,o=host.com', password
   
    if ldap.bind
        @point_person = PointPerson.find_by_username(username)
        if !@point_person.nil?
            return true
        end
    else
        return false
    end
  end  #authenticate_or_request_with_http_basic
end




=begin    
    conn.search( 'ou=users,ou=nyc,dc=corp,dc=google,dc=com',
	       LDAP::LDAP_SCOPE_SUBTREE, 'cn=*', ['cn']) do |x|
    count += 1
  end

 my $mesg = $ldap->search(
                          base   => SEARCH_BASE,
                          scope  => SEARCH_SCOPE,
                           filter => FIELD_EMPLOYEE_UID."=$employee_username"
                          );
=end